<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

  defined('_JEXEC') or die('Retricted Access');
  
  $tableList = JobBoardConstant::getFieldTypeList();
  $user = &JFactory::getUser();
  $controllerName = JRequest::getVar('controller');
  $limited = JRequest::getVar('limited', 0);
  $active = "sectiontableheader";
  $inactive = "";
  $backend_usertype = array(JBADMIN_USER, JBSUPERADMIN);
  
   JHTML::_('behavior.tooltip');
?>
<script type="text/javascript">
/* <![CDATA[ */
    function tableOrdering( order, dir, task ) {
        var form = document.adminForm;

        form.filter_order.value     = order;
        form.filter_order_Dir.value    = dir;
        form.task.value = task;
        form.submit();
    }
    
    function listItemTask( id, field, task ) {
        var f = document.adminForm;
        f.cid.value = id;
        f.boxchecked.value = 1;
        f.task.value = task;
        f.field.value = field;
        
        f.submit();
    }
    
    function submitbutton(pressbutton){
        var form = document.adminForm;
		if(pressbutton == "sendemail"){
			var sendmail = document.getElementById("sendmail");
			sendmail.style.display = "block";
		} else {
			form.task.value = pressbutton;
			form.submit();
		}
    }
/* ]]> */
</script>

<div id="jobboard-content">
<form name="adminForm" action="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=jaapplications&Itemid='.JRequest::getVar('Itemid')); ?>" method="post">

	<?php
		if ($this->items)
		{
	?>
		<table class="adminlist">
        	<thead>
				<tr>
					<th width="20" class="title">
						<?php echo JText::_( 'NUM' ); ?>
					</th>
					<th width="5%"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" /></th>
					<?php
					
                    for($i = 0, $n = count($this->fieldlist); $i < $n; $i++ ){
                    	
                        $field = $this->fieldlist[$i];
                        if($field->is_sortable){
                            $header = JHTML::_('grid.sort',   JText::_($field->label), $field->sort_field_name, @$this->lists['order_Dir'], @$this->lists['order'] );
                        } else {
                            $header = JText::_($field->label);
                        }
                        ?>
                        <th style="width:<?php echo $field->field_width;?>" class="title">
                            <?php echo  $header; ?>
                        </th>
                        <?php
                    }
                    ?>
                </tr>
			</thead>
			<tbody>
        	<?php
        	$items = $this->items;
        	$k = 0;
        	for($i = 0, $n = count($items); $i < $n; $i++){
        		$item = $items[$i];
        		$item->checked_out = '';
        		$checked 	= JHTML::_('grid.checkedout',   $item, $i );
        		?>
        		<tr class="<?php echo "row$k"; ?>">
            		<td><?php echo $this->pagination->getRowOffset($i); ?></td>
					<td align="center"><?php echo $checked; ?></td>
            		<?php
                    for($ii = 0, $nn = count($this->fieldlist); $ii < $nn; $ii++ ){
                        $field = $this->fieldlist[$ii];
                        $field_name = $field->field_name;
                        
                        $text = $item->$field_name;
                        $align="";
                        
                        $width_column = ($field->column_width!=0)?"width=\"".$field->column_width."%\"":"";
                    
                        if($field->field_type == "boolean" ){
                            $align = "align='center'";
                            $text = $this->getToggleLink($field_name, $item, $i);
                        } else if($field->field_type == "date" || $field->field_type == "datetime" ){
                            $text = date("d-M-Y", strtotime($text));
                        }
                        if($field->linked){
                            ?>
                            <td <?php echo $align; ?> <?php echo $width_column; ?>>
                                <?php if ($field->is_bold) echo '<strong>'; ?>
                                <?php 
                                if($field->field_name=='job_id'){
                                	$url = 'index.php?option=com_jajobboard&view=jajobs&task=edit&cid[]='.$item->id ;
                                }
                                else{
                                	$url = 'index.php?option='. JBCOMNAME .'&view=jaapplications&task=edit&cid[]='.$item->id;
                                }
                                ?>
                                <a href="<?php echo JRoute::_( $url ); ?>"><?php echo $text; ?></a>
                                <?php if ($field->is_bold) echo '</strong>'; ?>
                            </td>
                            <?php
                        } else {
                            ?>
                            <td <?php echo $align; ?> <?php echo $width_column; ?>>
                                <?php if ($field->is_bold) echo '<strong>'; ?>
                                <?php echo  $text; ?>
                            	<?php if ($field->is_bold) echo '</strong>'; ?>
                            </td>
                            <?php
                        }
                    }
                    ?>
                     
            	</tr>
        	<?php
        		$k = 1 - $k;
			}
        	?>
        	</tbody>
        	<tfoot>

				<tr>
					<th colspan="<?php echo count($this->fieldlist) + 3; ?>">
						<?php echo $this->pagination->getListFooter(); ?>
					</th>
				</tr>
			</tfoot>
		</table>
	<?php
		}
		else 
		{
			echo JText::_('Have no application');
		
	?>
		<a class="button" href="javascript:window.history.go(-1);"><?php echo JText::_('Back'); ?></a>	
	<?php
		}
	?>
	<input type="hidden" name="option" value="<?php echo JBCOMNAME; ?>" />
	<input type="hidden" name="view" value="jaapplications" />
    <input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
    <input type="hidden" name="menuId" value="<?php echo JRequest::getVar('menuId'); ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>	
 </form>
 </div>